package com.easyadmin.controller;

import com.easyadmin.annotation.GlobalInterceptor;
import com.easyadmin.entity.enums.PermissionCodeEnum;
import com.easyadmin.entity.query.SysOperationLogQuery;
import com.easyadmin.entity.vo.AjaxResponseVO;
import com.easyadmin.entity.vo.PaginationResult;
import com.easyadmin.service.SysOperationLogService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/api/settings")
public class SysOperationLogController extends ABaseController {

    final Logger logger = LoggerFactory.getLogger(getClass());

    @Resource
    private SysOperationLogService sysOperationLogService;

    /**
     *
     * @Description: 操作日志
     *
     * @auther: 多多洛
     * @date: 14:19 2020/11/21
     * @param: [query]
     * @return: AjaxResponseVO
     *
     */
    @RequestMapping("loadLogList")
    @GlobalInterceptor(permissionCode = PermissionCodeEnum.SETTINGS_OPERLOG)
    public AjaxResponseVO loadLogList(SysOperationLogQuery query) {
        try {
            query.setOrderBy("id desc");
            PaginationResult result = sysOperationLogService.findListByPage(query);
            return getSuccessResponseVO(result);
        } catch (Exception e) {
            logger.error("获取日志信息异常", e);
            return getServerErrorResponseVO();
        }
    }
}
